﻿using UnityEngine;
using System.Collections;

public class DragMoviment : MonoBehaviour 
{
	private Vector3 mousePosition;
	#region Controle do movimento do objeto.
	//velocidade do deslocamento
	public float moveSpeed = 0.05f;
	//controle para terminar o movimento completo entre o clique e sua posicao
	private bool destino=true;
	#endregion
	// Use this for initialization
	void Start () 
	{

	}

	// Update is called once per frame
	void Update () 
	{	
		//Dispara o deslocamento
		if (Input.GetMouseButtonDown(0)) 
		{
			mousePosition = Input.mousePosition;
			mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
			destino = false;
		}
		//Desloca o objeto
		if(destino==false)
		{

			transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
			if(transform.position == mousePosition)
			{
				destino = true;
			}
		}
	}
}